﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace EasyPath
{
    class WatermarkTextBox : TextBox
    {
        private string _nullText;

        public WatermarkTextBox()
        {
            NullText = "Enter a value";
            OnTextChanged(EventArgs.Empty);
        }

        public bool IsEmpty
        {
            get { return Text == "" || Text == NullText; }
        }

        public string NullText
        {
            get { return _nullText ?? ""; }
            set
            {
                if (Text == NullText)
                {
                    Text = value;
                }
                _nullText = value;
            }
        }

        protected override void OnEnter(EventArgs e)
        {
            if (Text == NullText)
            {
                Text = "";
            }
            ForeColor = Color.Black;
            base.OnEnter(e);
        }

        protected override void OnLeave(EventArgs e)
        {
            if (Text == "")
            {
                Text = NullText;
                ForeColor = Color.LightGray;
            }
            else
            {
                ForeColor = Color.Black;
            }
            base.OnLeave(e);
        }
    }
}
